package com.mzz.behavior.fatherandson.strategy;

/**
 * 决策者/拥有者
 *
 * @param <T>
 * @param <O1>
 * @param <O2>
 * @author xushijian
 * @date 18/5/16
 */
public class Context<T, O1, O2> {

    private Strategy<T, O1, O2> strategy;

    public Context(Strategy<T, O1, O2> strategy) {

        this.strategy = strategy;

    }

    /**
     * 获取策略
     *
     * @return 策略
     */
    public Strategy<T, O1, O2> getStrategy() {
        return strategy;
    }

    /**
     * 设置策略
     *
     * @param strategy 策略
     */
    public void setStrategy(Strategy<T, O1, O2> strategy) {
        this.strategy = strategy;
    }

    public T algorithm(O1 a, O2 b) {
        return strategy.algorithm(a, b);
    }

}
